﻿using System;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;

namespace UniAspect.UnityCommon.OptionalDependency
{
    [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false)]
    public sealed class OptionalDependencyAttribute : DependencyResolutionAttribute
    {
        public readonly string Name;

        public OptionalDependencyAttribute()
                : this(null)
        {

        }

        public OptionalDependencyAttribute(string name)
        {
            Name = name;
        }

        public override IDependencyResolverPolicy CreateResolver(Type typeToResolve)
        {
            return new OptionalDependencyResolver(typeToResolve, Name);
        }
    }
}